package com.tencent.sr.iris.activity.interfaces.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.tencent.sr.rmall.common.exception.TMallBizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 *
 */
@AllArgsConstructor
@Getter
public enum ActivityTypeEnum {
    /**
     * 月月领
     */
    MONTH_GIFT("MONTH_GIFT", "月月领"),
    REGIST_GIFT("REGIST_GIFT", "注册有礼"),
    INVITE_GIFT("INVITE_GIFT", "邀请有礼"),
    LEVEL_UP_FOSTER_GIFT("LEVEL_UP_FOSTER_GIFT", "升级有礼(培育奖)"),
    LEVEL_UP_PROMO_GIFT("LEVEL_UP_PROMO_GIFT", "升级有礼(晋升奖)"),
    GUIDE_ALLOWANCE("GUIDE_ALLOWANCE", "辅导津贴"),
    ;

    @JsonValue
    private final String code;
    private final String desc;

    public static ActivityTypeEnum getByCode(String code) {
        for (ActivityTypeEnum staff : ActivityTypeEnum.values()) {
            if (staff.getCode().equals(code)) {
                return staff;
            }
        }

        return null;
    }

    @JsonCreator
    public static ActivityTypeEnum jsonCreator(String code) {
        ActivityTypeEnum activityIdEnum = getByCode(code);
        if (activityIdEnum == null) {
            throw new TMallBizException("活动类型错误");
        }
        return activityIdEnum;
    }
}
